package icrts.logic;

import java.awt.Graphics;
import javax.swing.JPopupMenu;
import javax.swing.JMenuItem;
import java.util.HashSet;
import java.util.Iterator;

public abstract class AbstractGameObject {

	protected Position pos;
  protected String identifier = "";
	protected HashSet<String> menuOptions;
	protected JPopupMenu popupMenu;

	public AbstractGameObject(Position p){
		this.pos = p;
	}
	
	public Position getPos(){
		return pos;
	}

	// just needs to register the current object as a listener
	// for the timer class, which then calls the appropiate
  // display update
	public void update(){
//		Timer.addListener(this);
	}

	// prints the identifier of this objec
  public void printID() {
    System.out.println(this.identifier);
  }

	// methods to draw this object
	abstract public void draw(Graphics g, boolean selected);
	protected abstract Position findClosestFreeArea(int x, int y);

		// checks if the given "belongs" to / selects the game object
	abstract public boolean selects(int x, int y);	
	
	// obtains the specific JPopupMenu of this object
	abstract public JPopupMenu getJPopupMenu();
	protected void initJPopupMenu(){
		Iterator<String> it = menuOptions.iterator();
		String current;
		popupMenu = new JPopupMenu();
		JMenuItem menuItem;

		while ( it.hasNext() ){
			current = it.next();
			menuItem = new JMenuItem(current);
			//menuItem.addActionListener(this); 
			popupMenu.add(menuItem);
		}

	}
	
}
